//
// Created by none98 on 2021/9/14.
//

#ifndef LOGINSERVER_TIMESTAMP_H
#define LOGINSERVER_TIMESTAMP_H


class TimeStamp {
public:
    TimeStamp():
        seconds(0),
        microSeconds(0)
    {
    }

    TimeStamp(int hours, int minutes, int seconds, int milliseconds){
        this->seconds = hours*60*60+minutes*60+seconds;
        this->microSeconds = milliseconds*1000;
    }
    ~TimeStamp() = default;

    bool operator<(const TimeStamp &another)const{
        if(seconds<another.seconds) return true;
        else if(seconds==another.seconds and microSeconds<another.microSeconds)
            return true;
        else return false;
    }

    bool operator>(const TimeStamp &another) const{
        if(seconds>another.seconds) return true;
        else if(seconds==another.seconds and microSeconds>another.microSeconds)
            return true;
        else return false;
    }

    bool operator==(const TimeStamp &another) const{
        return seconds == another.seconds and microSeconds == another.microSeconds;
    }

    TimeStamp operator+(const TimeStamp &another){
        TimeStamp t;
        t.seconds=seconds+another.seconds+(another.microSeconds+microSeconds)/MICRO_SECONDS;
        t.microSeconds = (microSeconds+another.microSeconds)%MICRO_SECONDS;
        return t;
    }

    static TimeStamp NowTime();

    static const int MICRO_SECONDS = 1000000;


private:
    long seconds;
    int microSeconds;
};


#endif //LOGINSERVER_TIMESTAMP_H
